package com.example.animactivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private RecyclerView main1_rv;
    private Img1Adapter img1Adapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        main1_rv = findViewById(R.id.main1_rv);
        ArrayList<String> img_list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            img_list.add("test");
        }
        img1Adapter = new Img1Adapter(R.layout.main1_item_layout, img_list);
        main1_rv.setLayoutManager(new LinearLayoutManager(this));
        main1_rv.setAdapter(img1Adapter);
        // 例如
//        ActivityCompat.postponeEnterTransition(this);
//        ActivityCompat.startPostponedEnterTransition(this);

        img1Adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter, @NonNull View view, int i) {
                ImageView img1 = view.findViewById(R.id.img1);
                Intent intent = new Intent(MainActivity.this, MainActivity2.class);
                ViewCompat.setTransitionName(img1, "shared element");
                ActivityOptionsCompat sharedElement = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, img1, "shared element");
                // TransOneActivity, 启动方法没变;
                startActivity(intent, sharedElement.toBundle()
                );
            }
        });
    }
}